package Leetcode.array;

public class RemoveDuplicates {
    public int removeDuplicates(int[] nums) {
         int len=nums.length;
         if(len==0||len==1)
             return len;

         int j=0;
         int k=0;
         for(  int i=1;i<len;i++){
             if(nums[j]==nums[i]){
                 k++;
             }
             else {
                 nums[i-k]=nums[i];
                 j++;
             }
         }
         return len-k;
    }

    public static void main(String[] args) {
         int[] nums={1,1,2,2,3,4,5};
         RemoveDuplicates removeDuplicates=new RemoveDuplicates();
        System.out.println(removeDuplicates.removeDuplicates(nums));

        for (int i=0;i<nums.length;i++){
            System.out.println(nums[i]);
        }
    }
}
